package com.zw.yzk.kabu.data.repository;

import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.CheckUpdateEntity;
import com.zw.yzk.kabu.data.network.service.CheckUpdateService;
import com.zw.yzk.kabu.data.network.task.CheckUpdateTask;
import com.zw.yzk.kabu.data.network.task.Task;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class CheckUpdateRepository extends CommonRepository {


    @Inject
    public CheckUpdateRepository() {

    }

    @Override
    protected Observable connectServer(Task task) {
        CheckUpdateService service = ServiceGenerator.createService(CheckUpdateService.class);
        CheckUpdateTask checkUpdateTask = (CheckUpdateTask) task;

        return service.checkUpdate(checkUpdateTask.currentVersionCode);
    }

    @Override
    protected Func1<CheckUpdateEntity, Observable> getServerData() {
        return new Func1<CheckUpdateEntity, Observable>() {
            @Override
            public Observable call(CheckUpdateEntity entity) {
                return Observable.just(entity);
            }
        };
    }

}
